From : Alexander Wingrove (awingrove@thenet.co.uk)
Subject : A simple text editor
> First: Is there some kinda textbox-area thingy in GadgetToolbox to create
> this kinda textbox-area thing??
> If not, how can I read a 620x200 TEXT area in a window??????
As far as I know, the GadTools string gad does not support multiple lines
of text. Therefore, you'll have to do it yourself. The following code opens
a 640x200 window and allows text to be input. Basic text handling is
implemented ( backspace, return key ), but you can add the rest as you need
( a cursor would help :-) :
---8<--------------------------------------------------------
NoCli : WBStartup
Screen 0,12
Window 0,0,0,640,200,$140e,"Edit Test",1,2
WindowInput 0
WindowOutput 0
WLocate 0,0
sec.b=0
lin.w=0
text$=""
tick.b=0
finish.b=False
Repeat
Select Event
Case $200 ; close gadget
finish=True
Case $400 ; key press
key$=Inkey$
Select Asc(key$)
Case 13 ; return key
WLocate 0,WCursY+8
text$+Chr$(11) ; insert a line feed
Case 8 ; backspace key
If Len(text$) > 0
If NOT Right$(text$,1)=Chr$(11)
WLocate WCursX-8, WCursY ; remove last character
Print " " ; if it's not a line feed
WLocate WCursX-8, WCursY
text$=UnLeft$(text$,1)
EndIf
EndIf
Default ; any other key
Print key$
text$+key$
If WCursX>InnerWidth-8 ; check if reached end of window
WLocate 0,WCursY+8
text$+Chr$(11) ; line feed
EndIf
If WCursY>InnerHeight-8 ; check if reached bottom
finish=True
EndIf
End Select
End Select
Until finish=True
; here text$ holds the typed in text complete with line feeds
End
---8<--------------------------------------------------------
This all works as is so you can mess around with it a bit. Hope this helps.
I wrote it originally for a password protection program for my hard drive.
It's basically finished and works by replaceing LoadWB command with my own
that requests a password, so only you can load workbench. It also encrypts
harmful CLI commands ( delete, copy, rename, etc. ) so that they cannot be
used either until the correct password is entered. A GUI is used to
configure the prog. I've now have no use for it, but if anyone else wants
it, including the source code, let me know.